package com.woniuxy.thred.others;

/**
 * description: TimerTest01 <br>
 * date: 2022/2/6 4:40 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

import java.util.*;

/**
 * 任务调度：Timer 和TimerTask类
 */
public class TimerTest01 {
    public static void main(String[] args) {
        Timer timer = new Timer();
        //执行安排(执行任务一次)
//      timer.schedule(new MyTask(),1000);
        //执行多次
//      timer.schedule(new MyTask(),1000,200);
        //每个2秒执行一次，5秒后开始
        //timer.schedule(new MyTask(),new Date(5000l),200);
        Calendar cal = new GregorianCalendar(2022, 2, 6, 4, 55);
        timer.schedule(new MyTask(), cal.getTime(), 200);//指定时间
    }
}

//任务类
class MyTask extends TimerTask {

    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("放空大脑休息一会");
        }
        System.out.println("---------end----------");
    }
}